package simple.charlie.hibernate.controllers;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import simple.charlie.hibernate.book.entities.Book;

@RestController
@Transactional("bookTransactionManager")
public class BookController {
	@Autowired
	private SessionFactory sessionFactory;

	@RequestMapping(value = "/book", method = RequestMethod.GET)
	public void book(){
		System.out.println("BookController.sessionFactory: "+sessionFactory);
		Book book = new Book();
		book.setName("thinking in java");
		sessionFactory.getCurrentSession().persist(book);
	}
}
